<template>
  <div>
     <el-form ref="form" :model="goodslist">
      <el-form-item label="商品名称">
        <el-input v-model="goodslist.title"></el-input>
      </el-form-item>
      <el-form-item label="描述">
        <el-input v-model="goodslist.desc"></el-input>
      </el-form-item>
       <el-form-item label="详情">
        <el-input v-model="goodslist.detailUrl"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">更新</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { fecthById,update} from '@/api/goodslist.js'
export default {
 data() {
    return {
      goodslist: {}
    }
  },
  created() {
    fecthById({
      id: this.$route.params.id
    }).then(res => {
      console.log(res)
      this.goodslist = res.data
    })
  },
  methods: {
    onSubmit() {
      update(this.goodslist).then(res => {
        if (res.data.modified > 0) {
          this.$message({
            message: '更新成功',
            type: 'success'
          })
        } else {
          this.$message.error('更新失败')
        }
        this.$router.push('/goodslist/list')
      })
    },
    onCancel() {
      this.$router.push('/goodslist/list')
    }
  }
}

</script>
<style>
</style>